<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>我的准考证</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta name="apple-mobile-web-app-status-bar-style" content="default"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta name="format-detection" content="telephone=no"/>
    <script type="text/javascript" src="${s.base}/mobile/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="${s.base}/mobile/js/ajaxfileupload.js"></script>


    <link href="${s.base}/mobile/css/weui.min.css" rel="stylesheet" />
    <link href="${s.base}/mobile/css/jquery-weui.css" rel="stylesheet"/>
    <link href="${s.base}/mobile/css/jquery-weui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="${s.base}/mobile/css/enrollment/zzzs.css"/>
    <link href="${s.base}/mobile/css/zhkw.css" rel="stylesheet">
</head>
<body>
<div class="main-content75">
    <div class="photo-collect-ctn">
        <div class="photo-collect-nei">
            <h1>一寸照片采集</h1>
            <div class="weui-uploader__bd photo-collect-btn-group" id="showPhoto" data-objectId="${infoPhoto}">
                <div class="weui-uploader__input-box">
                    <input id="filePhoto" class="weui-uploader__input photo-collect-btn" name="file" onchange="imgUpload('filePhoto','kwmanagement/mult','showPhoto','${token}')" type="file" accept="image/*" multiple>
                </div>
            </div>
            <h1 class="red">${msg}</h1>
            <!--<div class="uploadbtn" id="commentImge">提交</div>-->
            <div class="zzzs-btn-ctn" style="margin-top:1.38rem;">
                <button type="button" id="commentImge">提交审核</button>
            </div>
            <h2>格式为.jpg，大小为5K～50K</h2>
        </div>
    </div>
</div>



</body>
<script type="text/javascript" src="${s.base}/mobile/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/jquery-weui.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/fontSize.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/common.js"></script>
<script type="text/javascript">
    var applyId = '${applyId}';
    var token = '${token}';

    $(function(){
     //获取一寸照片等信息
        var objectId = "${infoPhoto}";
        if(isNotBlank(objectId)){
            showPhoto(objectId,"showPhoto");
        }

    })

    $("#commentImge").on("click",function () {
        initMySocietyData()
    });

    function initMySocietyData() {
        //如果是正在审核
        var str = '${msg}';
        if(str=="正在审核"){
            $.toast("照片正在审核,请勿重复上传", "text");
            return false;
        }

        var attaObjectId = $("#showPhoto").attr("data-objectId");//附件id
        if(attaObjectId==""){
            $.toast("请先上传图片在提交", "text");
            return false;
        }
        $.fn.doPost('/phone/kwmanagement/upStudentOneImage', {applyId:applyId,token:token,objectidOne:attaObjectId,examine:"2"}, function (result) {
            if (result.code === 0) {
                $.toast('一寸照片上传成功', "text");
                window.location.href = "/phone/kwmanagement/studentMian?token=${token}&applyId=${applyId}";

            } else {
                $.toast('获取数据失败', "text");
            }
        });

    }
    function showPhoto(objectId, showId) {
        $.post("/sysFile/list", {"objectId": objectId}, function (result) {
            if (result.code == 0 && result.data != null && result.data.length > 0) {
                for (var i = 0; i < result.data.length; i++) {
                    var obj = result.data[i];
                    addImage(obj.id,obj.objectId,obj.path,showId);
                }
            } else {
                $("#"+showId).attr("data-objectId","");
            }
        }, "json");
    }

    function imgUpload(objId, catalog, showId,token) {
        var objectId = $("#" + showId).attr("data-objectId");
        $.showLoading("图片上传中");
        $.ajaxFileUpload({
            //处理文件上传操作的服务器端地址(可以传参数,已亲测可用)
            url: '/sysFile/singleImageNoMerber?objectId=' + objectId + '&catalog='+catalog+'&token=${releaseId}',
            secureuri: false,                   //是否启用安全提交,默认为false
            fileElementId: objId,                //文件选择框的id属性
            dataType: 'json',                    //服务器返回的格式,可以是json或xml等
            success: function (rows) {
                $.hideLoading();
                //服务器响应成功时的处理函数
                if (rows.code == 0) {
                    addImage(rows.data.id,rows.data.objectId,rows.data.path,showId);
                } else {
                    //parent.alertBoxFalse("上传失败");
                    $.toast("上传失败", "text");
                }
            }
        });
    }

    function addImage(id,objectId,path, showId) {
        var str = '';
        str += '<div class="weui-uploader__file"><img onclick="showImg(\'' + id + '\')" src="/sysFile/showFileByPath?path='+ path +'" style="file"/>';
        str += '<div class="weui-gallery" onclick="hideImg()" id="img_' + id + '" style="display: none"><div class="filepic"><img class="" src="/sysFile/showFileByPath?path=' + path + '"/></div>';
        str += '<div class="weui-gallery__opr"><a href="javaScript:void(0)" class="weui-gallery__del"><i onclick="deleteImage(this,\'' + id + '\',\''+showId+'\')" class="weui-icon-delete weui-icon_gallery-delete"></i></a></div></div>';
        str += '</div>';
        $("#" + showId).prepend(str);
        $("#showPhoto .weui-uploader__input-box").hide();
        $("#" + showId).attr("data-objectId", objectId);
    }

    function deleteImage(obj, id, showId) {
        //如果他把图片删除掉来的话
        var str = '${msg}';
        if(str=="正在审核"){
            $.toast("照片正在审核,请勿删除", "text");
            return false;
        }
        $.post("/sysFile/deleteById", {id: id}, function (result) {
            if (result.code === 0) {
                $("#"+showId).attr("data-objectId","");
                $("#img_" + id).hide();
                $("#showPhoto .weui-uploader__input-box").show();
                $(obj).parent().parent().parent().parent().remove();
            }
        });
    }



</script>

</html>
